define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'episode/script/index' + location.search,
                    add_url: 'episode/script/add',
                    edit_url: 'episode/script/edit',
                    del_url: 'episode/script/del',
                    multi_url: 'episode/script/multi',
                    import_url: 'episode/script/import',
                    table: 'episode_script',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'producer.name', title: __('Producer.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'media_id', title:"媒资文件ID"},
                        {field: 'file', title: __('File'), operate: false, formatter: Table.api.formatter.file},
                        {field: 'score', title: __('Score'), operate:'BETWEEN'},
                        {field: 'score_num', title: __('Score_num')},
                        {field: 'like_num', title: __('Like_num')},
                        {field: 'dou_num', title: __('Dou_num')},
                        {field: 'is_banner', title: __('Is_banner'), searchList: {"1":__('Is_banner 1'),"2":__('Is_banner 2')}, formatter: Table.api.formatter.normal},
                        {field: 'video_type', title: __('Video_type'), searchList: {"1":__('Video_type 1'),"2":__('Video_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.normal},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'yes_money', title: __('Yes_money'), operate:'BETWEEN'},
                        {field: 'dan_money', title: __('Dan_money'), operate:'BETWEEN'},
                        {field: 'character_num', title: __('Character_num'), operate:'BETWEEN'},
                        {field: 'character_num_nv', title: __('Character_num_nv'), operate:'BETWEEN'},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                        buttons: [
                            {
                                name: 'detail',
                                text:function(row){
                                    return "剧情人物"
                                },
                                title:function(row){
                                    return __('【'+row.name+'】人物管理')
                                },
                                classname: 'btn btn-xs btn-primary btn-dialog chakan',
                                icon: 'fa fa-book fa-fw',
                                url: 'episode/character?episode_script_id={ids}',
                            },
                            {
                                name: 'detail',
                                text:function(row){
                                    return "章节列表"
                                },
                                title:function(row){
                                    return __('【'+row.name+'】章节管理')
                                },
                                classname: 'btn btn-xs btn-primary btn-dialog chakan',
                                icon: 'fa fa-book fa-fw',
                                url: 'episode/chapter?episode_script_id={ids}',
                            },
                        ],
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
